package com.atguigu.base;

import com.atguigu.util.CastUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.io.Serializable;
import java.util.Map;

/**
 * @author lhh
 * @ClassName BaseServiceImpl
 * @date 2022/9/14 14:41
 */

public abstract class BaseServiceImpl<T> implements BaseService<T> {

    protected abstract BaseDao<T> getEntityDao();

    public int save(T t) {
        return getEntityDao().save(t);
    }

    public T getById(Serializable id) {
        T t=getEntityDao().getById(id);
        return t;
    }

    public int update(T t) {
        return getEntityDao().update(t);
    }

    public int remove(Serializable id) {
        return getEntityDao().remove(id);
    }

    public PageInfo<T> findPage(Map<String, Object> filters) {
        //当前页数
        int pageNum = CastUtil.castInt(filters.get("pageNum"));
        //每页显示的记录条数
        int pageSize = CastUtil.castInt(filters.get("pageSize"));

        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<T>(getEntityDao().findPage(filters));
    }

}
